package ru.compft.web.beans;

import ru.compft.web.WebConst;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import java.io.Serializable;
import java.util.Locale;

/**
 * User: VVasiliev
 * Date: 07.06.12
 * Time: 13:12
 * Бин отвечающий за смену локали на странице
 */
@ManagedBean(name = WebConst.LOCALE_BEAN)
@SessionScoped
public class LocaleBean implements Serializable {
    private static final long serialVersionUID = 4826489421720322377L;

    private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();

    public Locale getLocale() {
        return locale;
    }

//    public void setLocale(Locale locale) {
//        this.locale = locale;
//    }

    public String getLanguage() {
        return locale.getLanguage();
    }

    public void setLanguage(String language) {
        locale = new Locale(language);
        FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
    }
}
